import { type MockMethod } from 'vite-plugin-mock';
import MockJs from 'mockjs';
import { menuData, userData } from '../constant';
import { RequestParams, resultSuccess, resultError } from '../utils';

export default [
  {
    url: '/api/login',
    method: 'post',
    response: (request: RequestParams) => {
      const { username, password } = request.body;
      const userItem = userData.find(item => item.username === username);
      if (!userItem && password) {
        return resultError('该用户不存在');
      }
      return resultSuccess({
        token: MockJs.Random.guid(),
        userInfo: userItem
      });
    }
  },
  {
    url: '/api/getMenuPermission',
    method: 'post',
    response: () => {
      return resultSuccess(menuData);
    }
  }
] as MockMethod[];
